<!DOCTYPE HTML>
<html>
<head>
<title>If Var [not] between LowerBound and UpperBound | AutoHotkey</title>
<meta name="description" content="The &quot;if Var between Low and High&quot; statement checks whether a variable's contents are numerically or alphabetically between two values (inclusive)." />
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>If var [not] between LowerBound and UpperBound</h1>

<p>根据数值或字母顺序检查<a href="../Variables.htm">变量的</a>内容是否在两个值之间(包含边界).</p>

<pre class="Syntax">
<span class="func">if</span> Var <span class="func">between</span> LowerBound <span class="func">and</span> UpperBound
<span class="func">if</span> Var <span class="func">not between</span> LowerBound <span class="func">and</span> UpperBound
</pre>
<h2>参数</h2>
<dl>

  <dt>Var</dt>
  <dd><p>需要被检查的<a href="../Variables.htm">变量</a>名称.</p></dd>

  <dt>LowerBound</dt>
  <dd><p>指定范围的下限, <em>Var</em> 必须大于或等于此字符串, 数字或变量引用.</p></dd>

  <dt>UpperBound</dt>
  <dd><p>指定范围的上限, <em>Var</em> 必须小于或等于此字符串, 数字或变量引用.</p></dd>

</dl>

<h2>备注</h2>
<p>如果这三个参数都为纯数值, 那么它们将被作为数字而不是字符串进行比较. 其他情况下, 它们将被作为字符串按字母顺序进行比较(即字母次序将决定 <em>Var</em> 是否在指定范围内). 此时, 可以使用 <code><a href="StringCaseSense.htm">StringCaseSense</a> On</code> 来设置在比较时区分大小写.</p>
<p class="warning"><strong>警告</strong>: 运算符 "between", "is", "in" 和 "contains" 不支持用于<a href="../Variables.htm#Expressions">表达式</a>中.</p>
<h2>相关</h2>
<p><a href="IfEqual.htm">IfEqual/Greater/Less</a>, <a href="IfIn.htm">if var in/contains MatchList</a>, <a href="IfIs.htm">if var is type</a>, <a href="IfInString.htm">IfInString</a>, <a href="StringCaseSense.htm">StringCaseSense</a>, <a href="EnvAdd.htm">EnvAdd</a><a href="Block.htm">, 区块</a>, <a href="Else.htm">Else</a></p>
<h2>示例</h2>
<pre class="NoIndent">if var between 1 and 5
    MsgBox, %var% is in the range 1 to 5, inclusive.

if var not between 0.0 and 1.0
    MsgBox %var% is not in the range 0.0 to 1.0, inclusive.

if var between %VarLow% and %VarHigh%
    MsgBox %var% is between %VarLow% and %VarHigh%.

if var between blue and red
    MsgBox %var% is alphabetically between the words blue and red.

LowerLimit = 1
UpperLimit = 10
InputBox, UserInput, Enter a number between %LowerLimit% and %UpperLimit%
if UserInput not between %LowerLimit% and %UpperLimit%
    MsgBox Your input is not within the valid range.</pre>

</body>
</html>